﻿@using admin.Model
@{
    ViewData["Title"] = "BookAuthorInfo";
    Layout = "~/Views/Shared/_SmallWinLayout.cshtml";
    var BookAuthor = Model as AuthorOfBook;
    var AuthorList = ViewData["authorlist"] as List<Author>;
}

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 图书管理 <span class="c-gray en">&gt;</span> 修改图书作者信息 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">已添加作者：<strong>@BookAuthor.authors.Count</strong>个</span>
        <span class="r">共有数据：<strong>@BookAuthor.authors.Count</strong> 条</span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-hover table-bg table-sort">
            <thead>

                <tr class="text-c">
                    <th width="20%">作者ID</th>
                    <th width="20%">作者名</th>
                    <th width="20%">图书ID</th>
                    <th width="20">图书名</th>
                    <th width="20%">操作</th>
                </tr>
            </thead>
            <tbody>
                @for (int i = 0; i < BookAuthor.authors.Count; i++)
                {
                    <tr class="text-c">
                        <td>@BookAuthor.authors[i].Id</td>
                        <td><a title="查看作者信息" onclick="author_show('作者详细信息','/Home/AuthorShow','500','350','@BookAuthor.authors[i].Id')" href="javascript:;">@BookAuthor.authors[i].Name</a></td>
                        <td>@BookAuthor.book.Id</td>
                        <td>@BookAuthor.book.Name</td>
                        <td class="td-manage">
                            <a title="删除" href="javascript:;" onclick="del_author(this,'/Home/BookAuthorDel','@BookAuthor.authors[i].Id','@BookAuthor.book.Isbn')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
</div>


<div class="page-container">
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">可选作者：<strong>@AuthorList.Count</strong>个</span>
        <span class="r">共有数据：<strong>@AuthorList.Count</strong> 条</span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-hover table-bg table-sort">
            <thead>

                <tr class="text-c">
                    <th width="15%">作者ID</th>
                    <th width="20%">作者名</th>
                    <th width="15%">电话</th>
                    <th width="25">地址</th>
                    <th width="15%">合同</th>
                    <th width="10%">操作</th>
                </tr>
            </thead>
            <tbody>
                @for (int i = 0; i < AuthorList.Count; i++)
                {
                    <tr class="text-c">
                        <td>@AuthorList[i].Id</td>
                        <td><a title="查看作者信息" onclick="author_show('作者详细信息','/Home/AuthorShow','500','350','@AuthorList[i].Id')" href="javascript:;">@AuthorList[i].Name</a></td>
                        <td>@AuthorList[i].Phone</td>
                        <td>@AuthorList[i].Address</td>
                        @if (AuthorList[i].IsContact.Equals("1"))
                        {
                            <td>已签</td>
                        }
                        else
                        {
                            <td>未签</td>
                        }
                        <td class="td-manage">
                            <a title="添加" href="javascript:;" onclick="add_author(this,'/Home/BookAuthorAdd','@AuthorList[i].Id','@BookAuthor.book.Isbn')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe600;</i></a>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
</div>


<script type="text/javascript">
    //删除图书作者信息
    function del_author(obj, url, aid, isbn) {
        url = url + "?aid=" + aid + "&isbn=" + isbn;
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                type: 'POST',
                url: url,
                success: function (response) {
                    if (response == "ok") {
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!', { icon: 1, time: 2000 });
                        self.setInterval(function () {  // 这个方法是说在延迟两秒后执行大括号里的方法
                            window.location.reload();   // 这个方法是刷新当前页面
                        }, 2000); //这里2000代表两秒
                        //window.location.reload();
                    }
                    else
                        layer.msg('删除失败! ', { icon: 5, time: 3000 });
                },
                error: function (response) {
                    layer.msg('删除失败!', { icon: 5, time: 3000 });
                },
            });
        });
    }


    //添加图书作者信息
    function add_author(obj, url, aid,isbn) {
        url = url + "?aid=" + aid + "&isbn=" + isbn;
        layer.confirm('确认要添加吗？', function (index) {
            $.ajax({
                type: 'POST',
                url: url,
                success: function (response) {
                    if (response == "ok") {
                        $(obj).parents("tr").remove();
                        layer.msg('已添加!', { icon: 1, time: 2000 });
                        self.setInterval(function () {  // 这个方法是说在延迟两秒后执行大括号里的方法
                            window.location.reload();   // 这个方法是刷新当前页面
                        }, 2000); //这里2000代表两秒
                        //window.location.reload();
                    }
                    else
                        layer.msg('添加失败! ', { icon: 5, time: 3000 });
                },
                error: function (response) {
                    layer.msg('添加失败!', { icon: 5, time: 3000 });
                },
            });
        });
    }

    /*作者-详情*/
    function author_show(title, url, w, h, id) {
        url = url + '?id=' + id;
        layer_show(title, url, w, h);
    }

</script>